package com.zlm.user.emp.controller;

import com.zlm.common.base.BaseController;
import com.zlm.common.constants.CodeConstants;
import com.zlm.common.dto.JsonResultDto;
import com.zlm.user.emp.service.EmpPositionSignService;
import com.zlm.user.emp.service.SysUnderlingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 求职用户报名-controller
 * @Author: duyufu
 * @Date: 2019/5/6 17:42
 */
@RestController
@RequestMapping(value = "/sign")
public class EmpPositionSignController extends BaseController {

    @Autowired
    private SysUnderlingService sysUnderlingService;
    @Autowired
    private EmpPositionSignService empPositionSignService;

    @GetMapping("/empSignUp")
    public JsonResultDto empSignUp(Integer pracId, Integer empId) {
        try {
            //查询是否有合伙人
            List<Integer> partList =  sysUnderlingService.queryUnderlingList(empId);
            if (partList.size() == 0) {
                return fail(CodeConstants.CODE_10011);
            }
            Integer count = empPositionSignService.countEmpPositionSign(pracId,empId);
            if (count > 0 ) {
                return fail(CodeConstants.CODE_10012);
            }
            //添加报名记录
            empPositionSignService.saveEmpPositionSign(partList,pracId,empId);
            //TODO 向职业顾问推送消息



            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return fail(CodeConstants.CODE_BUSY);
        }
    }
}
